import re

count = 0

def get_assert_summary():
    return {"已优化的assert数量": count}

def manage_assert(content):

    global count

    pattern = (
        "if\s+([^{}]*?)\s+\{\}\s+else\s+{\n"
        "\s+__assert_fail\(([^{}]*?)\);\n"
        "\s*\}\n\s*\'c_(\d+):\s+\{\n"
        "\s+if\s+([^{}]*?)\s+\{\}\s+else\s+{\n"
        "\s+__assert_fail\(([^{}]*?)\);\n"
        "\s*\}\n\s*\};"
    )
    # 替换匹配的模式为assert!宏
    replacement = r'assert!(\1);'

    count += len(re.findall(pattern, content, re.VERBOSE))

    # 使用re.sub进行替换，re.VERBOSE允许跨行匹配
    converted_code = re.sub(pattern, replacement, content, flags=re.VERBOSE)

    converted_code = converted_code.replace('extern \"C\" {}\n', '')

    return converted_code
